﻿@using Kendo.Mvc.UI.Fluent
@using StevensReceipts.Domain
@model IEnumerable<StevensReceipts.Domain.ChartofAccount>

@{
    ViewBag.Title = "Chart of Accounts";
}

<h2>Index</h2>

@Html.ActionLink("Create New Chart of Account", "Create");

<div id="chartofaccounts">
    @(Html.Kendo().TabStrip()
            .Animation(false)
           .Name("tabstrip")
           .Items(tabstrip =>
                      {

                          tabstrip.Add().Text("All Accounts").Selected(true).Content(
                              @<text>@(Html.Kendo().Grid(Model) 
                                           .Name("GridAll")
                                           .Columns(columns =>
                                                        {
                                                            columns.Bound(c => c.Code);
                                                            columns.Bound(c => c.Name);
                                                            columns.Bound(c => c.AccountType.Name);
                                                            columns.Bound(c => c.TaxRate.Name);
                                                        })
                                           .Groupable()
                                           .Scrollable(s=>s.Enabled(true)))</text>);
                          
                          foreach (ChartofAccountCategory category in ViewBag.AccountCategories)
                          {
                              
                              //constructure the inner list

                              var ca = category.Types;
                              var caName = category.Name;
                              tabstrip.Add().Text(category.Name)
                                  .Content(@<text>@(Html.Kendo().Grid(Model.Where(c => ca.Contains(c.AccountType)))
                                  .Name("Grid"+caName)
                                  .Columns(columns =>
                                               {
                                                   columns.Bound(c => c.Code);
                                                   columns.Bound(c => c.Name);
                                                   columns.Bound(c => c.AccountType.Name);
                                                   columns.Bound(c => c.TaxRate.Name);
                                               })
                                  .Groupable().Scrollable(s=>s.Enabled(true)))</text>);
                          }
                      }

           )
    )
</div>
